package com.glsc.ngateway.common.base.converter.oaflow;

import com.alibaba.excel.util.CollectionUtils;
import com.glsc.ngateway.common.api.oaflow.dto.oaflow.WorkflowBaseDto;
import com.glsc.ngateway.common.base.domain.oracle.ecology.WorkflowBase;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * @author xuchang
 */
public class WorkflowBaseConverter {

    public static WorkflowBaseDto do2Dto(WorkflowBase domain) {
        if (Objects.isNull(domain)) {
            return null;
        }
        return WorkflowBaseMapper.INSTANCE.do2Dto(domain);
    }

    public static List<WorkflowBaseDto> do2Dto(List<WorkflowBase> domainList) {
        return CollectionUtils.isEmpty(domainList) ? java.util.Collections.emptyList() : domainList.stream().map(WorkflowBaseConverter::do2Dto).collect(Collectors.toList());
    }

    public static WorkflowBase dto2Do(WorkflowBaseDto dto) {
        if (Objects.isNull(dto)) {
            return null;
        }
        return WorkflowBaseMapper.INSTANCE.dto2Do(dto);
    }

    public static List<WorkflowBase> dto2Do(List<WorkflowBaseDto> dtoList) {
        return CollectionUtils.isEmpty(dtoList) ? java.util.Collections.emptyList() : dtoList.stream().map(WorkflowBaseConverter::dto2Do).collect(Collectors.toList());
    }

    @Mapper(componentModel = "spring")
    public interface WorkflowBaseMapper {

        WorkflowBaseMapper INSTANCE = Mappers.getMapper(WorkflowBaseMapper.class);

        WorkflowBaseDto do2Dto(WorkflowBase domain);

        List<WorkflowBaseDto> do2Dto(List<WorkflowBase> domain);

        WorkflowBase dto2Do(WorkflowBaseDto dto);

        List<WorkflowBase> dto2Do(List<WorkflowBaseDto> dto);
    }
}
